/*
 * Copyright (C) 2011 Markus Junginger, greenrobot (http://greenrobot.de)
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.zhongketech.sunflower.transport.gentest;

import de.greenrobot.daogenerator.DaoGenerator;
import de.greenrobot.daogenerator.Entity;
import de.greenrobot.daogenerator.Property;
import de.greenrobot.daogenerator.Schema;
import de.greenrobot.daogenerator.ToMany;
import de.greenrobot.daogenerator.ToOne;

/**
 * Generates entities and DAOs for the example project DaoExample.
 * 
 * Run it as a Java application (not Android).
 * 
 * @author Markus
 */
public class ZkDaoGenerator {

	public static void main(String[] args) throws Exception {
		Schema schema = new Schema(2, "com.zhongketech.sunflower.transport.model");


		addUsers(schema);
		addAuthorizations(schema);
		addSmsCode(schema);
		addRequest(schema);
		addContact(schema);
		addMyApplications(schema);
		addSupervision(schema);

		new DaoGenerator().generateAll(schema, "../../../Xiaoxuntong/src");
	}


	private static void addSupervision(Schema schema)
	{
		
		Entity mySupervision = schema.addEntity("MySupervision");
//		mySupervision.addIdProperty()
		mySupervision.addStringProperty("mySupervisionId").notNull().primaryKey();
	
		Entity controlInfo = schema.addEntity("Supervision");
		// 鎺у埗绛栫暐闂
		Property strategyId = controlInfo.addStringProperty("id").notNull().primaryKey()
				.getProperty();
		controlInfo.addStringProperty("type");
		controlInfo.addStringProperty("title");
		controlInfo.addBooleanProperty("enable");
		controlInfo.addIntProperty("priority");
		mySupervision.addToMany(controlInfo, strategyId).setName("supervisons");
		
		// 鏃堕棿娈�
		Entity timeInfo = schema.addEntity("Times");
		timeInfo.addIntProperty("start_at");
		timeInfo.addIntProperty("end_at");
		Property timeId = timeInfo.addStringProperty("timeId").notNull().primaryKey().getProperty();
//		timeInfo.addToOne(controlInfo, id);
		controlInfo.addToMany(timeInfo, timeId).setName("time_segments");;
		
		
		
		Entity eyeInfo = schema.addEntity("EyeProtect");
		eyeInfo.addBooleanProperty("enable");
		eyeInfo.addIntProperty("use_time");
		eyeInfo.addIntProperty("rest_time");
		eyeInfo.addStringProperty("epId").notNull().primaryKey();
//		controlInfo.addToOne(eyeInfo, strategyId).setName("eyes_protect");
		
		// app info
		Entity applicationInfo = schema.addEntity("ApplicationControl");
		applicationInfo.setTableName("APP");
		applicationInfo.addStringProperty("enable");
		applicationInfo.addStringProperty("acId").notNull().primaryKey();
//		controlInfo.addToOne(applicationInfo, strategyId).setName("application");
		
		Entity applications = schema.addEntity("Applications");
//		applications.addStringProperty("id").primaryKey();
		applications.addStringProperty("app_name");
		applications.addBooleanProperty("enable");
		applications.addStringProperty("image_url");
		Property applicationsId = applications.addStringProperty("id").notNull().primaryKey()
				.notNull().getProperty();
		applicationInfo.addToMany(applications, applicationsId).setName("applications");

		Entity CallInfo = schema.addEntity("Call");
		CallInfo.addBooleanProperty("enable");
		CallInfo.addStringProperty("callId").notNull().primaryKey();
//		controlInfo.addToOne(CallInfo, strategyId).setName("call");

		Entity SmsInfo = schema.addEntity("Sms");
		SmsInfo.addBooleanProperty("enable");
		SmsInfo.addStringProperty("networkId").notNull().primaryKey();
//		controlInfo.addToOne(SmsInfo, strategyId).setName("sms");

		Entity ScreenInfo = schema.addEntity("ScreenLock");
		ScreenInfo.addBooleanProperty("enable");
		ScreenInfo.addStringProperty("screenLockId").notNull().primaryKey();
//		controlInfo.addToOne(ScreenInfo, strategyId).setName("screen_lock");

		Entity NetworkInfo = schema.addEntity("Network");
		NetworkInfo.addBooleanProperty("enable");
		NetworkInfo.addStringProperty("networkId").notNull().primaryKey();
//		controlInfo.addToOne(NetworkInfo, strategyId).setName("network"); 
		
		//special_nums
		Entity specialNums = schema.addEntity("SpecialNums");
		Property specialNumsId = specialNums.addStringProperty("id").notNull().primaryKey()
				.getProperty();
		specialNums.addStringProperty("type");
		specialNums.addStringProperty("phone");
		specialNums.addStringProperty("name");
		specialNums.addStringProperty("group");
		mySupervision.addToMany(specialNums, specialNumsId).setName("special_nums");
		
	}


	private static void addSmsCode(Schema schema) {
		Entity smsCode = schema.addEntity("SmsCode");
		smsCode.addIdProperty();
		smsCode.addStringProperty("smscode").notNull();
	}

	private static void addMyApplications(Schema schema) {
		Entity myApplications = schema.addEntity("MyApplicationsInfo");
		myApplications.addStringProperty("id").notNull();
		myApplications.addStringProperty("package_name");
		myApplications.addStringProperty("app_name");
		myApplications.addStringProperty("image_url");
	}

	private static void addContact(Schema schema)
	{
		Entity myContacts = schema.addEntity("MyContacts");
		myContacts.addIdProperty().notNull();

		Entity contactInfo = schema.addEntity("Contact");
		contactInfo.addStringProperty("id");
		contactInfo.addStringProperty("group");
		contactInfo.addStringProperty("contactId");
		contactInfo.addStringProperty("visible_id");
		contactInfo.addStringProperty("name");
		contactInfo.addStringProperty("role");
		contactInfo.addStringProperty("gender");
		contactInfo.addStringProperty("birthday");
		contactInfo.addStringProperty("phone");
		contactInfo.addStringProperty("avatar_url");
		Property myContactsId = contactInfo.addLongProperty("myContactstId").notNull().getProperty();
		myContacts.addToMany(contactInfo, myContactsId).setName("contacts");
		
	}

	private static void addRequest(Schema schema)
	{
		Entity myRequest = schema.addEntity("MyRequest");
		myRequest.addIdProperty();
		//    	requestInfo.addStringProperty("type");

		Entity request = schema.addEntity("Request");
		//    	Property userFk = userInfo.addStringProperty("id").primaryKey()
		//				.getProperty();
		request.addStringProperty("id");
		request.addStringProperty("type");
		request.addStringProperty("from");
		request.addStringProperty("to");
		request.addStringProperty("create_at");
		request.addStringProperty("text");
		request.addStringProperty("state");
		Property myRequestId = request.addLongProperty("myRequestId").notNull().getProperty();
		myRequest.addToMany(request, myRequestId).setName("requests");
	}


	private static void addAuthorizations(Schema schema) {

		/*-------------------- User part -------------------------*/
		Entity authorizationsInfo = schema.addEntity("Authorizations");
		Property authorizationsFk = authorizationsInfo.addStringProperty("id").notNull().primaryKey()
				.getProperty();
		authorizationsInfo.addStringProperty("session_token");
		authorizationsInfo.addStringProperty("visible_id");
		authorizationsInfo.addStringProperty("role"); 
		authorizationsInfo.addStringProperty("phone"); 
		authorizationsInfo.addStringProperty("gender");
		authorizationsInfo.addStringProperty("name"); 
		authorizationsInfo.addStringProperty("birthday"); 
		authorizationsInfo.addStringProperty("avatar_url"); 
	}

	private static void addUsers(Schema schema) {

		/*-------------------- User part -------------------------*/
		Entity userInfo = schema.addEntity("User");
		Property userFk = userInfo.addStringProperty("id").notNull().primaryKey()
				.getProperty();
		userInfo.addStringProperty("visible_id");

		userInfo.addStringProperty("role"); 
		userInfo.addStringProperty("phone"); 
		userInfo.addStringProperty("password");
		userInfo.addStringProperty("gender");
		userInfo.addStringProperty("name"); 
		userInfo.addStringProperty("birthday"); 
		userInfo.addStringProperty("avatar_url"); 

		Entity schoolInfo = schema.addEntity("School");
		schoolInfo.addStringProperty("schoolId");
		schoolInfo.addStringProperty("school_name");
		schoolInfo.addStringProperty("userKey").notNull().primaryKey();
		ToOne one = userInfo.addToOne(schoolInfo, userFk);
		one.setName("school");

		Entity classInfo = schema.addEntity("Classes");
		classInfo.addStringProperty("id");
		classInfo.addStringProperty("classes");
		classInfo.addStringProperty("grade");
		classInfo.addStringProperty("userKey").primaryKey().notNull();
		userInfo.addToOne(classInfo, userFk);

		Entity parents = schema.addEntity("Parents");
		parents.addIdProperty();
		Property myParentsId = userInfo.addLongProperty("myParentsId").notNull().getProperty();
		ToMany many = parents.addToMany(userInfo, myParentsId);
		many.setName("parents");
	}

}
